//
//  MCSpecialTrainTableCell.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/19.
//

import UIKit
import JKSwiftExtension

class MCSpecialTrainTableCell: UITableViewCell {
    
    let specialTraingingTableCellIdentifier = "specialTraingingTableCellIdentifier"
    
    
    @IBOutlet weak var specialCollectionView: UICollectionView!
    
    
    private var specializedTrainingDataSource:Array = ["肩颈","手臂","胸部","背部","腹部","臀部","大腿","小腿","全身"]
    private var specializedTrainingImageDataSource:Array = ["plan_jin_image","plan_arm_image","plan_chest_image","plan_bodyback_image","plan_abdomen_image","plan_buttocks_image","plan_thigh_image","plan_shank_black_image","plan_whole_body_image"]
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        let specialCollectionViewLayout = UICollectionViewFlowLayout.init()
        specialCollectionView.setCollectionViewLayout(specialCollectionViewLayout, animated: true)
        specialCollectionView.dataSource = self
        specialCollectionView.delegate = self
        specialCollectionView.register(UINib.init(nibName: "MCSpecialCollectionCell", bundle: Bundle.main), forCellWithReuseIdentifier: specialTraingingTableCellIdentifier)
        specialCollectionView.isScrollEnabled = false
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

         
    }
    
}

extension MCSpecialTrainTableCell:UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
        return 5
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        return 5
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSizeMake((self.contentView.frame.size.width - 30)/3, 75)
    }
    
    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.specializedTrainingDataSource.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell:MCSpecialCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: specialTraingingTableCellIdentifier, for: indexPath) as! MCSpecialCollectionCell
        
        cell.headerImageView.image = UIImage(named:self.specializedTrainingImageDataSource[indexPath.row] as String)
        cell.titleLabel.text = self.specializedTrainingDataSource[indexPath.row] as String
        
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let createPlanVc = MCAddCreatePlanVc.init()
        UIApplication.jk.topViewController()?.navigationController?.pushViewController(createPlanVc, animated: true)
        
    }
    
}
